<?php require ('setcookie.html'); 
$_SESSION['logini'] = isset($_SESSION['logini']) ? $_SESSION['logini'] : false;

//this sets all variables, that are SUPPOSED TO BE USED FOR TEXT VISIBLE FOR USERS
//all text is encapsulated in the array-variable $LRV
//DO NOT set this variable yourself, if you want to change text, change right in language_related_variables 
require 'language_related_variables.php';

$language_decoder=array('de'=>"german", 'en'=>"english", 'es'=>"spanish", 'ru'=>"russian");
$url_part_array= explode(".", $_SERVER['SERVER_NAME']);
$site_language_short=$url_part_array[0];
if ($site_language_short == 'lingomoto') {$site_language_short = 'en';}
$site_language= $language_decoder[$site_language_short];
if (!$site_language){$site_language="german";$site_language_short="de";}
$LRV=filter_by_language($site_language);

// read configuration
switch($site_language_short)
    {
        case 'de': require ('konfiguration.html');require ('nutzer.html');break;
        case 'es': require ('configuracion.html');require ('usuario.html');break;
        case 'ru': require ('configuration.html');require ('user.html');break;
        case 'en': require ('configuration.html');require ('user.html');break;
        default: require ('configuration.html');require ('user.html');
    }

//variables that can be used in functions when declared "global" ---- 
$customerid = $_SESSION['customerid'];
$lang_info=language_info();
$can_lang=$lang_info[0]; //'german'
$learn_lang=$lang_info[1];
$langpair=$lang_info[2];
//if (!$customerid and $_REQUEST['owner_choice']=='own') print ' <meta http-equiv="refresh" content="0; URL='.'http://de.lingomoto.com/registrieren.html'.'">';
$_SESSION["display_language"]=$site_language;
require ('ajaxrater/_drawrating.php');

$link = $_SERVER['PHP_SELF'];
$langen = 'word-lists.html';
$langes = 'listas-vocablos.html';
$langru = 'word-lists.html';
$langde = 'vokabellisten.html';


// read header
$html=<<<AAA
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="{$site_language_short}">
<head>
    <title>{$LRV['title_tag']['vocable_lists']}</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="{$LRV['description_meta_tag']['vocable_lists']}" />
    <meta name="language" content="{$site_language_short}" />
    <link href="style.css" type="text/css" rel="stylesheet" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
	
	<!-- for the foreign name field and the single list field-->
	<link rel="stylesheet" href="autocomplete/jquery.autocomplete.css" type="text/css" />
	<script type="text/javascript" src="autocomplete/jquery142min.js"></script>
	<script type="text/javascript" src="autocomplete/jquery.autocomplete.min.js"></script>
	<script type="text/javascript" src="autocomplete/jquery.autocomplete.pack.js"></script>
	<script type="text/javascript" src="autocomplete/jquery.autocomplete.js"></script>
     
     <!-- for the rating bars - folder="ajaxrater" googlesearch="unobtrusive ajax rater"-->
    <script type="text/javascript" src="ajaxrater/js/behavior.js"></script>
    <script type="text/javascript" src="ajaxrater/js/rating.js"></script>
    <link rel="stylesheet" type="text/css" href="ajaxrater/css/rating.css" />
    
    <!-- <script type="text/javascript" src="extern.js"></script>-->
    
<!-- to every image in "Aktionen" there is a tooltip, that shows up,
when you hover over it. explains in words what will happen, when you click the image 
CSS FOR TOOLTIP-->  
<style type="text/css">
#dhtmltooltip{
position: absolute;
border: 1px solid grey;
width: 90px;
padding: 2px;
background-color: lightyellow;
visibility: hidden;
z-index: 100;
filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=115);
}
</style>


</head>

<body id="trainer">
<div id="dhtmltooltip"></div> <!-- the div comes here, because it doesnt matter where in the code it comes,
the shown tooltip has a fixed position through css-->
AAA;
print $html;

?>
<script type="text/javascript">

var offsetxpoint=-60 //Customize x offset of tooltip ü
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}
function foreign_username()
{
   //alert(document.getElementById('foreign_name').id);
    element=document.getElementsByName('owner_choice');
    setCheckedValue(element,'foreign');
   element2=document.getElementById('foreign_name');
   if (element2.value=='Username') element2.value='';
   if (element2.value=='Benutzername') element2.value='';
   if (element2.value=='Nombre de usuario') element2.value='';
   if (element2.value=='Имя пользователя') element2.value='';
   //this.value='';

}
function list_names2()
{
   
   element2=document.getElementById('list_names');
   if (element2.value=='Description of list') element2.value='';
   if (element2.value=='Beschreibung der Liste') element2.value='';
   if (element2.value=='Descripción de la lista') element2.value='';
   if (element2.value=='Наименование списка слов') element2.value='';
   
   //this.value='';

}
function focus_foreign()
{
   element=document.getElementById("foreign_name");
   element.focus();

}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


document.onmousemove=positiontip


$(document).ready( function()
  {
     $("#foreign_name").autocomplete("foreign_username.php").result(function(event, item, formatted)
	 
	 {
         //$(this).parents().find("form:first").submit();
		 //$("<li>").html("Selected: " +item).appendTo("#result");
     }  
                                            );
	 $("#list_names").autocomplete("list_names.php").result(function(event, item, formatted)
	 
	 {
         $(this).parents().find("form:first").submit();
		 //$("<li>").html("Selected: " +item).appendTo("#result");
     }  
                                            );										
  
  }
  
);
    
</script>
<?php


//helping functions for normal and error printing 
function b() {print '<br/>';} function n() {print "\n";} function bn() {print "<br/>\n";}

function mysql_query_secure($query)
{
	//print $query;
   $result=mysql_query($query);//print $query;
   if ( ! $result ) { die('Error query : ' . mysql_error()); }
   return $result;
}

//for $can_lang,$learn_lang and $langpair
function language_info()
{
       global $customerid;
	   $result = mysql_query_secure( "SELECT can,learn,langpair FROM settings where customerid = '$customerid'" );
	  
       if (mysql_num_rows($result)<>0) $line = mysql_fetch_array( $result, MYSQL_ASSOC);
	   return array($line['can'],$line['learn'],$line['langpair']);

}

function selection_options()
{
   global $customerid,$site_language,$LRV;
   //define order of mysql_query by either: frequency of list download, date, average rating
   if ($_REQUEST['order']=='newest' or $_REQUEST['order']=='') $order= "ORDER BY date DESC";
   elseif ($_REQUEST['order']=='most_frequent') $order= "ORDER BY popularity_count DESC";
   else $order= "ORDER BY total_value/total_votes DESC";
   
   //define weather certain languages are set in mysql-query 
   if ($_REQUEST['first_lang']=='all' or $_REQUEST['first_lang']=='') $first_lang="";
   else $first_lang=" AND langpairs_{$site_language}.can='".$_REQUEST['first_lang']."'";
   if ($_REQUEST['second_lang']=='all' or $_REQUEST['second_lang']=='') {$second_lang="";}
   else $second_lang=" AND langpairs_{$site_language}.learn='".$_REQUEST['second_lang']."'";
   
   //who owns the lists?
   
   if ($_REQUEST['owner_choice']=='own') {if ($customerid)$owner_choice=' AND vocable_lists.customerid='.$customerid.' ';}
   elseif ($_REQUEST['owner_choice']=='foreign')$owner_choice=' AND vocable_lists.username LIKE "'.$_REQUEST['foreign'].'" ';
   
   //does the list include a certain word or word group
   if ($_REQUEST['list_names'] != $LRV['text_input_filling']['list_name']) { $word_group=' AND vocable_lists.listname LIKE "%'.$_REQUEST['list_names'].'%" '; }
   else { $word_group = ''; }
   
   
   return " $owner_choice $word_group $first_lang $second_lang $order";
}
function print_lists()
{
   global $can_lang,$learn_lang, $langpair,$customerid,$LRV,$site_language;

   //determine the page number  and save as hidden input
   //page number means which 20 entries are shown from beginning
   if (!$_REQUEST['weitere_listen_x'] and !$_REQUEST['vorherige_listen_x'])
	  $current_page=0;
   elseif ($_REQUEST['weitere_listen_x'])
	  $current_page=$_REQUEST['page']+1;
   elseif ($_REQUEST['vorherige_listen_x'])
	  $current_page=$_REQUEST['page']-1;	  
   print "<input type=\"hidden\" name =\"page\" value=\"$current_page\"  >";
   $limit =$current_page*17;
   //bring together mysql-query with all the options
   $selection_options=selection_options();
   $query="SELECT langpairs_{$site_language}.can,langpairs_{$site_language}.learn,vocable_lists.username,vocable_lists.listname, vocable_lists.listid,
      vocable_lists.popularity_count,vocable_lists.date,vocable_lists.customerid,   
      vocable_lists.total_votes,vocable_lists.total_value 
   FROM vocable_lists, langpairs_{$site_language}
   WHERE langpairs_{$site_language}.langpairid=vocable_lists.langpair".// AND vocable_lists.listid=ratings.listid  
   "$selection_options ".
   "LIMIT $limit,21";
   
   $res=mysql_query_secure($query);
   $num_rows=mysql_num_rows($res);
   //begin: table with lists
   print "<div class=\"marginleft1\" >";
   print '<table border="0" style="border-collapse:collapse">';
 //  print "<table class=\"bordered\" >";
   print "         <tr>"; //header row of table
   print "            <th WIDTH=\"25%\" align=\"left\" >{$LRV['list_table_column_titles'][0]}</th>";
   print "            <th WIDTH=\"8%\" align=\"left\" >{$LRV['list_table_column_titles'][1]}</th>";
   print "	      <th WIDTH=\"8%\" align=\"left\" >{$LRV['list_table_column_titles'][2]}</th>";
   print "	      <th WIDTH=\"14%\" align=\"left\" >{$LRV['list_table_column_titles'][3]}</th>";
   print "	      <th WIDTH=\"5%\" >{$LRV['list_table_column_titles'][6]}</th>";
   print "	      <th WIDTH=\"5%\" >{$LRV['list_table_column_titles'][4]}</th>";
   print "	      <th WIDTH=\"5%\" >{$LRV['list_table_column_titles'][5]}</th>";
 //  print "	      <th>{$LRV['list_table_column_titles'][6]}</th>";
   print "	      <th WIDTH=\"14%\">{$LRV['list_table_column_titles'][7]}</th>";
   print "         </tr>";
   print "         <tr><td>&nbsp;</td></tr>"; 
   if ($res)
   {
   $dark_colour=True;//initiating variables
   while ($row=mysql_fetch_array($res) and $intCount<20)
   {
     $list_name=$row[3];$user_name=$row[2]; $can_lang=$row[0];  $learn_lang=$row[1]; $list_id=$row[4];
     $popularity_count=$row[5]; $current_customerid=$row[7];
     $count+=1; 
     $date=$row[6];$intCount++;
   
     if ($row['total_votes'])$average_rating=round($row['total_value']/$row['total_votes'],1);
     else $average_rating='-';
     $rating_count=$row['total_votes'];
     $timestamp=strtotime($date); $date=date('d.m.o',$timestamp);//converting to right time format
     //data_rows of table
   
     // qty of words in list
     $query5="SELECT * from vocable_lists_words where listid = $list_id";
     $res5=mysql_query_secure($query5);
	 $qty_words = mysql_num_rows($res5);
     
     print "     <tr class=\"lineheight\" >";
		$dark_colour=!$dark_colour;//for styling purposes every second row has the class="bg" and is darker
		if ($dark_colour) {print '<td align="left" >'; } 
		   else {             print '<td align="left" class="bg">'; }
     print " $list_name </td>";
		if ($dark_colour) {print '<td align="left" >'; } 
		   else {             print '<td align="left" class="bg">'; }
     print " $can_lang </td>";
		if ($dark_colour) {print '<td align="left" >'; } 
		   else {             print '<td align="left" class="bg">'; }
     print " $learn_lang </td>";
		if ($dark_colour) {print '<td align="left" >'; } 
		   else {             print '<td align="left" class="bg">'; }
     print "$user_name</td>";
		if ($dark_colour) {print '<td>'; } 
		   else {             print '<td class="bg">'; }
     print "$qty_words</td>";
		if ($dark_colour) {print '<td>'; } 
		   else {             print '<td class="bg">'; }
     print "$popularity_count</td> ";
		if ($dark_colour) {print '<td>'; } 
		   else {             print '<td class="bg">'; }
     print "$average_rating ($rating_count)</td>"; 
     print "        <td>";
     //image as input type -> image link in "Aktionen"
     print "	       <input type =\"image\"  alt=\"Test\" src=\"/{$LRV['link_path']}/auge.jpg\" name=\"view$count\" value=\"Ansehen\"";
     //every image link does get its own number(view$count) to lateron know of which list the clicked image has been 
     print "	         onMouseover=\"ddrivetip('{$LRV['image_links_tooltip']['view']}','', 120)\"";
     print "             onMouseout=\"hideddrivetip()\"> ";
     print "           <input type =\"image\" src=\"/{$LRV['link_path']}/plus_b.png\" name=\"add$count\" value=\"Hinzufuegen\"";
     print "             onMouseover=\"ddrivetip('{$LRV['image_links_tooltip']['add']}','', 120)\"";
     print "             onMouseout=\"hideddrivetip()\" >";
	
	 if ($customerid){
	 print "           <input type =\"image\" src=\"/{$LRV['link_path']}/star2.jpg\" name=\"view$count\" value=\"Ansehen\"";
     print "             onMouseover=\"ddrivetip('{$LRV['image_links_tooltip']['rate']}','', 120)\"";
     print "             onMouseout=\"hideddrivetip()\" >";}

     if ($current_customerid==$customerid)
        {     //editing and deleting lists can only be done by the user how created the list
        print "           <input type =\"image\"  src=\"/{$LRV['link_path']}/edit.png\" name=\"edit$count\" value=\"Editieren\"";
        print "		     onMouseover=\"ddrivetip('{$LRV['image_links_tooltip']['edit']}','', 120)\"";
        print "              onMouseout=\"hideddrivetip()\" >";
        print "	          <input type =\"image\"  src=\"/{$LRV['link_path']}/papierkorb_a.png\" name=\"delete$count\" value=\"Loeschen\"";
        print "	             onMouseover=\"ddrivetip('{$LRV['image_links_tooltip']['delete']}','', 120)\"";
        print "              onMouseout=\"hideddrivetip()\" >";
	}
     print "       </td>";
     print "     </tr>"	  ;
   
   }
   }
   print "</table><div>";//end:table with lists //
   print '<br>';  
   
   if($current_page) {
		//    print "<input type=\"submit\" name=\"vorherige_listen\" value=\"<<{$LRV['button_last20']}\">";
	print "<input type=\"image\" name =\"vorherige_listen\" src=\"/{$LRV['link_path2']}/button_last20.png\" alt=\"<<{$LRV['button_last20']}\" title=\" <<{$LRV['button_last20']} \" />";
	}
	//when more then 20 lines are found you can click on "Weiter" to view the next 20
	if ($num_rows==21) { 
		//	print "<input type=\"submit\" name =\"weitere_listen\" value=\"{$LRV['button_next20']}>>\">";
	print "<input type=\"image\" name =\"weitere_listen\" src=\"/{$LRV['link_path2']}/button_next20.png\" alt=\"{$LRV['button_next20']}>>\" title=\" {$LRV['button_next20']}>> \" />";
	}
	//to every number of the image links the matching list_id from the db is sent
   if ($res and mysql_num_rows($res)>0)
   {  mysql_data_seek($res, 0);$count=0;
      while ($row=mysql_fetch_array($res))
      {  $list_name=$row[3];$user_name=$row[2]; $can_lang=$row[0];  $learn_lang=$row[1]; $list_id=$row[4];
	 $count+=1;
         print "<input type =\"hidden\" name=\"list_id$count\" value=\"$list_id\">" ;
      }
   }
   else //if no matching lists are found: either -> no lists with these options there or
        //->query did not work out, which happens, when there is no customerid, because it is a guest, that came from 
	//an email, because of a recommendation of a vocable list  
   {  // if ($customerid) print "Keine passenden Listen gefunden.";
		print $LRV['message_no_lists_found'];
      // else print "Du hast noch keine eigenen Listen, da du noch nicht angemeldet bist. Melde dich an und ".
      //            'erstelle eigene Listen! <a href="http://de.lingomoto.com/registrieren.html">Jetzt registrieren.</a>';
   }		  
}
function print_list_change_page($list_id,$view,$edit,$delete,$add,$delete_row)
{
   global $LRV,$site_language;
   print "<h2>{$LRV['page_title']['vocable_lists']}</h2>";b();

   print '<div class="content_frame">';
   print '    <div id="test_div"></div>';
   $action="Ansehen";
   print "<form name=\"xxx\" action=\"$link\" method=\"post\" >";
   print "   <input type=\"submit\" name =\"zurueck\" value=\"{$LRV['button_back']}\">";   b();
   
   if ($delete) {$view=$delete; print $LRV['actions_descriptions']['delete'];$action="Loeschen";}
   if ($edit)   {$view=$edit;   print $LRV['actions_descriptions']['edit'];$action="Editieren";}
   if ($add)    {$view=$add;    print $LRV['actions_descriptions']['add'];$action="Hinzufuegen";}  
   if ($_REQUEST['undo_rating']) undo_rating($list_id);
   //print $delete_row .'$delete_row';
   if ($delete_row) delete_row($delete_row);   
   
   //submitted image link and matching list_id again transferred via hidden input (its for when the user clicks "Weiter")
   print "   <input type=\"hidden\" name=\"submit$view\" value=\"$action\">"; 
   print "   <input type=\"hidden\" name=\"list_id$view\" value=\"$list_id\">    ";
   
   $query="SELECT langpairs_". $site_language . ".can,langpairs_". $site_language . ".learn,vocable_lists.username,vocable_lists.listname, vocable_lists.listid 
   from vocable_lists, langpairs_". $site_language . " WHERE langpairs_". $site_language . ".langpairid=vocable_lists.langpair AND vocable_lists.listid=$list_id ";
   $res=mysql_query($query); 
   
   $row=mysql_fetch_array($res); 
   
   
   print "<div>";
   print "<div style=\"width:200px; float:left;\">";
   print "<span >{$LRV['single_list_info']['name']}:</span><br/>";
   print "<span >{$LRV['single_list_info']['languages']}:</span><br/>"; 
   print "<span >{$LRV['single_list_info']['author']}:</span>";
   print "</div>";
   print "<div style=\"width:200px;float:left;\">";
   if ($edit) print "<b><input type=\"text\" name =\"list_name\" value=\"{$row[3]}\"></b><br/> ";
   else       print "<b>{$row[3]}</b><br/>";
   print "<b>{$row[0]}-{$row[1]}</b><br/>";
   print "<b>{$row[2]}</b><br/>";
   print "</div>";
   
   $next_page=$_REQUEST['page']+1;
   if (!$_REQUEST['weiter'] and !$_REQUEST['vorher'])
	  $current_page=0;
   elseif ($_REQUEST['weiter'])
	  $current_page=$_REQUEST['page']+1;
   elseif ($_REQUEST['vorher'])
	  $current_page=$_REQUEST['page']-1;	  
   print "<input type=\"hidden\" name =\"page\" value=\"$current_page\"  >";
   print "<div style=\"float:right;\">";
   print rating_bar($list_id,'10');
 //  print "<input type=\"submit\" name=\"undo_rating\" value=\"X\">";  BUILT INTO rating_bar
   print "</div>";
   print "</div>";
   print "<div style=\"clear:both;\">";
   if ($delete)    print "<input type=\"submit\" name =\"loeschen\" value=\"{$LRV['actions_description']['delete']}\">";
   elseif ($edit)  print "<input type=\"submit\" name =\"editieren\" value=\"{$LRV['actions_description']['edit']}\">";
   else            print "<input type=\"submit\" name =\"hinzufuegen\" value=\"{$LRV['actions_description']['add']}\">"; 
   
   $_SESSION["latest_list_id"]=$list_id; //when clicking on the link for adding vocables, it is possible
   //print $_SESSION["latest_list_id"];
   //to show the correct list in the select field
   $strLinkFromPagetitle= str_replace(" ", "-", strtolower($LRV["page_title"]["new_vocables"])).".html";
   if ($site_language=="russian") $strLinkFromPagetitle="individual-words.html";
   printHtmlLink($strLinkFromPagetitle, $LRV["insert_new_vocables"]);b();b();
   print "<b>{$LRV['title_translation_view']}:</b>";b();b();
   print "</div>";
    
  
     
     
    $limit =$current_page*20;//starting point of the lines fetched by mysql_query depends on the page number
    //page 0 -> first 20 lines, page 1 -> second 20 lines    
    mysql_query("SET NAMES 'utf8'");
    $query="SELECT id,1art,1word,2art,2word,3art,3word,
	art1,word1,art2,word2,art3,word3 from vocable_lists_words WHERE listid=$list_id order by 1word,2word,3word LIMIT $limit,21";
    $res=mysql_query($query);$num_rows=mysql_num_rows($res);//print $query;
    
    if ($num_rows)
    {
	    //printing the words and translations of the current list in a table
	    
	    //surrounding div with pseudo-format for giving parent element to any child element with
	    //formatted position-attribute
	    //-> an "absolute" positioning is relative to its first formatted parent window
    	print '<div style="position:relative;top:1px;">';
	    //this div is a layer above all text-> prevents copying
	    print '<div style="z-index:100;left:15px;top:10px;width:720px;height:490px;position:relative"></div>';
	    //needs to have absolute positioning, else if it will go visibly under the div
	    print '<table border="0" style="border-collapse:collapse;left:0px;top:0px;position:absolute">';
	    print '   <tr><th colspan ="3">'.$LRV['table_translation_titles']['words'].
			'</th><th colspan ="3">'.$LRV['table_translation_titles']['translations'].'</th></tr>';
	    
	    $dark_colour=True;$count=0;//initiating variables
	    while ($row=mysql_fetch_array($res) and $count <20)
	    {
		   $id=$row['id'];
	    	   $dark_colour=!$dark_colour;//for styling purposes every second row has the class="bg" and is darker
		   if ($dark_colour) {print '   <tr>'; } 
		   else {             print '   <tr class="bg">'; }
		   print '   <td><input type="submit" name="delete_row'.$id.'" value="X"></td>';
		   for($a=1;$a<=12; $a++)
		   {
		                       
		   	//print "      <td class='table6'><input type=\"text\" value =\"{$row[$a]}\" style=\"background-color:transparent;border:0px;width:60px;\"></td>";
							print "      <td class='table6'>{$row[$a]}</td>";
		   }
		                      print "</tr>";
							  $count++;
	   }
	   
	   
	  
	   print "</table>";b();

	   //action button is on top and at the button of the list
	   if ($delete)       print "<input type=\"submit\" name =\"loeschen\" value=\"{$LRV['actions_description']['delete']}\">";
	   elseif ($edit)     print "<input type=\"submit\" name =\"editieren\" value=\"{$LRV['actions_description']['edit']}\">";
	   else               print "<input type=\"submit\" name =\"hinzufuegen\" value=\"{$LRV['actions_description']['add']}\">";  
	   
	   //if not first page
	   if($current_page)              print "<input type=\"submit\" name=\"vorher\" value=\"<<{$LRV['button_last20']}\">";
	   
	   //when more then 20 lines are found you can click on "Weiter" to view the next 20
	   if ($num_rows==21) print "<input type=\"submit\" name =\"weiter\" value=\"{$LRV['button_next20']}>>\">   ";
   }
   else print $LRV["message_no_vocables_in_list"].
              " <input type=\"submit\" name =\"loeschen\" value=\"{$LRV['actions_description']['delete']}\">";;
   
     
   print "</div></form></div>";
}
function print_all_lists_page()
{
   global $site_language,$LRV;

   if ($_REQUEST['loeschen']) {delete_list(); }
   if ($_REQUEST['hinzufuegen']) {add_list(); }
   if ($_REQUEST['editieren']) {edit_list(); }

   
   print "<h2>{$LRV['page_title']['vocable_lists']}</h2>";b();

   print '<div class="content_frame">';
   print '    <div id="test_div"></div>';
     
   print "<div>{$LRV['message_choosable_lists']}:</div><br>";
   print '<form name="form1" method="post">';
   
   //find out which of the order options is currently selected and put it into variable
   if ($_REQUEST['order']=='newest') $newest= 'SELECTED';
   if ($_REQUEST['order']=='most_frequent') $most_frequent= 'SELECTED';
   if ($_REQUEST['order']=='best_rated') $best_rated= 'SELECTED';
  // if ($_REQUEST['order']=='own') $own= 'SELECTED';
  // if ($_REQUEST['order']=='foreign') $foreign= 'SELECTED';
   
   print '<div>';

   //select "Ausgangssprache"
   print '   <div class="fleft">';
   print "      <div>{$LRV['list_table_select_first_language']}</div>";
   print '         <select name= "first_lang" onchange="document.form1.submit();">';
   print "            <option value=\"all\">{$LRV['option_all_languages']}</option>";
   $res= mysql_query("SELECT distinct can from langpairs_". $site_language . " order by can ");
   while ($row = mysql_fetch_array($res))
   {  $language=$row['can']; 
      if ($_REQUEST['first_lang']==$language)$selected='SELECTED';
      print "            <option value=\"$language\" $selected>$language</option>";$selected='';}
   print '         </select>';
   print '      </div>';
   
   //select "Lernsprache"
   print '   <div class="fleft2">';
   print "      <div>{$LRV['list_table_select_second_language']}</div>";
   print '         <select name= "second_lang" onchange="document.form1.submit();">';
   print "            <option value=\"all\">{$LRV['option_all_languages']}</option>";
   $res= mysql_query("SELECT distinct can from langpairs_". $site_language . " order by can ");
   while ($row = mysql_fetch_array($res))
   {  $language=$row['can']; 
      if ($_REQUEST['second_lang']==$language)$selected='SELECTED';
      print "            <option value=\"$language\" $selected>$language</option>";$selected='';}
   print '         </select>';
   print '      </div>';
   //print_r ($_REQUEST);

   print '   <div class= "fleft2">';
   print "      <div>{$LRV['list_table_select_order_message']}</div>";
   print '         <select name="order" onchange="document.form1.submit();">';
   print '            <option value="newest" '.$newest.">{$LRV['list_table_select_order_options'][0]}</option>";
   print '            <option value="most_frequent" '.$most_frequent.">{$LRV['list_table_select_order_options'][1]}</option>";
   print '            <option value="best_rated" '.$best_rated.">{$LRV['list_table_select_order_options'][2]}</option>";
   print '         </select>';
   print '   </div>';

   print '</div>';
   
   if ($_REQUEST['owner_choice']=='own') $mine='checked="checked"';
   elseif ($_REQUEST['owner_choice']=='foreign') $foreign='checked="checked"';
   else $all='checked="checked"'; //when owner_choice was 'all' or on the first view of the site 
   
   if($_REQUEST['foreign']) $foreign_username=$_REQUEST['foreign']; else $foreign_username=$LRV['text_input_filling']['user_name'];
   print '<div class="fright">';
  //   print '   <span>'.$LRV['lable_list_authors'].':</span>';
   print '   <div style="height:18px;">';
   print '      <input type="radio" name="owner_choice" id="all" value="all" onchange="document.form1.submit();" '.$all.'>';
   print '      <label for="all">'.$LRV['list_table_select_author_options'][0].'</label>';
   print '   </div>';
   print '   <div>';
   print '      <input type="radio" name="owner_choice" id="own" value="own" onchange="document.form1.submit();" '.$mine.'>';
   print '      <label for="own">'.$LRV['list_table_select_author_options'][1].'</label>';
   print '   </div>';
   print '   <div>';
   print '   <input type="radio" name="owner_choice" id="foreign" value="foreign" onchange="focus_foreign();" '.$foreign.'>';
   print '   <label for="foreign">'.$LRV['list_table_select_author_options'][2].'</label>';
   print '   <input type="text" name="foreign" id="foreign_name" style="margin-left:3px;" value="'.$foreign_username.'" onfocus="foreign_username();"
   onkeypress="{if (event.keyCode==13)document.form1.submit();}" />';
   print '<input type="submit" style="margin-left:3px;width:30px;" name="Senden" value="GO" >';
   print '   </div>';
   print '</div>';   
  // if ($_REQUEST['order']=='foreign')$extra_value=$_REQUEST['extra'];
  // print '<div class="fleft"><div>(Nutzername)</div> <input type="text" name="extra" value="'.$extra_value.'" ></div>';
   
   //in case the user has no javascript or wants to submit on his on account
   //usually page is submitted when changing the selection options
   
   
   $selection_options=selection_options();
   $query="SELECT vocable_lists.listname 
   FROM vocable_lists, langpairs_". $site_language . "
   WHERE langpairs_{$site_language}.langpairid=vocable_lists.langpair AND vocable_lists.listid=vocable_lists.listid
   $selection_options";
   $res= mysql_query($query); 
   
   
   if($_REQUEST['list_names']) $list_names=$_REQUEST['list_names']; else $list_names=$LRV['text_input_filling']['list_name'];
   //when someone clicks into the field (event is onfocus) the field is emptied if there has not yet something been written
   print '<div style="float:left; clear:both; ">';
   print '<br>';  
   print '<span>'.$LRV['lable_list_contains'].'</span>';
   print '<input type="text" id="list_names" name="list_names" style="margin-left:3px;" value="'.$list_names.'" onfocus="list_names2();"
   onkeypress="{if (event.keyCode==13)document.form1.submit();}" />';
   print '<input type="submit" style="margin-left:3px;width:30px;" name="Senden" value="GO" >';
   print '</div>';

   print '   <div id="block20">';
   print '   <br>';  
   print '   <a  href="'.$LRV['new_wordlist'].'.html"> '.$LRV['link_create_vocable_list'].'</a>';
   print '   </div>'; 
   
   print '</div>';
   print_lists();
   print '</div>';
   print '</form>';
   
   print '</div>';
   
//   print '</div>';
}
function undo_rating ($list_id)
{
	global $customerid;
	require('ajaxrater/_config-rating.php');
	$objResult=mysql_query_secure("SELECT * FROM `$rating_dbname`.$rating_tableName WHERE listid=$list_id");
	$objRow=mysql_fetch_array($objResult);
	preg_match_all("/,$customerid:(.*?),/" , $objRow["used_customer_ids"],$arrMatches);
	$vote_value=$arrMatches[1][0];
	//print $vote_value;
	if ($vote_value)
	{
		$new_used_customer_ids=preg_replace("/,$customerid:.*?,/" , "," , $objRow["used_customer_ids"]);
		//print $objRow["used_customer_ids"];b();
		//print $new_used_customer_ids;b();
		$new_total_value=$objRow["total_value"]-$vote_value;
		$new_total_votes=$objRow["total_votes"]-1;
		
		$objResult = mysql_query_secure(
					"UPDATE `$rating_dbname`.$rating_tableName ".
					"SET used_customer_ids ='$new_used_customer_ids', ".
					"total_value = $new_total_value, ".
					"total_votes = $new_total_votes ".
					"WHERE listid=$list_id ");
	}
}

function delete_row($row_id)
{
	mysql_query("DELETE FROM vocable_lists_words WHERE id ={$row_id}");
}
function deletion_conditions_fullfilled($list_id)
{
   //right now it is not yet decided which conditions it will be so this is only a placeholder
   return False;
}
function delete_list()
{
   global $LRV, $site_language;
   //find submitted image link and matching list_id
   for ($count=1; $count<=20; $count++)
   {
      if ($_REQUEST["submit$count"] and !$zurueck)$delete=$count;
   }
   $list_id= $_REQUEST["list_id$delete"];
   
   if (deletion_conditions_fullfilled($list_id)) //sometimes the lists will be deleted (for example if it is rated bad,
                                                 //has too less words, has no rating or almost no downloads)
						 //->right now NO LIST will actually be deleted
   {
      $query= "DELETE FROM vocable_lists WHERE listid=$list_id";
      $resource=mysql_query($query);
   
      $query= "DELETE FROM vocable_lists_words WHERE listid=$list_id";
      $resource=mysql_query($query);   
   }
   
   else // -> this is what always happens, because deletion_conditions_fullfilled is just a placeholder (right now) and
   {    //always returns false
        //lists that are supposed to be deleted are taken over by the user "Lingomoto"
        $query= "UPDATE vocable_lists SET customerid=68, username='Lingomoto' WHERE listid=$list_id"; //customerid 0 means it belongs to all the catched lists, user is  
        $resource=mysql_query($query);                   //called "Lingomoto"
   
   }
   
   print "<font class='red'>{$LRV['message_list_deleted']}</font><br><br>";
}

function add_list()
{
   global $customerid, $langpair,$LRV,$site_language,$site_language_short;
   //find submitted image link and matching list_id
   
   if (!$customerid) {print $LRV['message_listadd_first_register'].'<a href="http://'. $_SERVER['SERVER_NAME'] . '/'.$LRV['register'].'.html">'.$LRV['register_now'].'</a>';} 
 //  <meta http-equiv="refresh" content="3; URL='.'http://de.lingomoto.com/registrieren.html'.'">';}
   else
   {
   for ($count=1; $count<=20; $count++)
   {
      if ($_REQUEST["submit$count"] and !$zurueck)$add=$count;
   }	
   $list_id= $_REQUEST["list_id$add"];
   
   //popularity_count raise by one
   $query="UPDATE vocable_lists SET popularity_count=popularity_count+1 WHERE listid=$list_id";
   $res=mysql_query_secure($query);
   
   //find words by list_id in word table of lists
   $query="SELECT 1word,1art,2word,2art,3word,3art,
	word1,art1,word2,art2,word3,art3 from vocable_lists_words where listid=$list_id";
   $res=mysql_query($query);
   
    $listid= mysql_insert_id();    
    while ($row=mysql_fetch_array($res))
    {	
	      $query3="SELECT 1word from wordbox0 WHERE customerid='". $customerid . "' AND 1word='{$row[0]}' AND word1='{$row[6]}'" ;$result=mysql_query_secure($query3);
		  if (mysql_num_rows($result)==0)
          {		  
          $query2="INSERT INTO wordbox0 (1word,1art,2word,2art,3word,3art,
	      word1,art1,word2,art2,word3,art3, customerid,boxid,langpairid) VALUES".
          " ('{$row[0]}','{$row[1]}','{$row[2]}','{$row[3]}','{$row[4]}','{$row[5]}','{$row[6]}','{$row[7]}'
		  ,'{$row[8]}','{$row[9]}','{$row[10]}','{$row[11]}',$customerid,0,$langpair)";
		  $res2=mysql_query($query2);   // print $query2;
          }		  
     } 
   $query= "SELECT langpair,customerid from vocable_lists WHERE listid='$list_id'"; 
   $result=mysql_query_secure($query);
   $row=mysql_fetch_array($result);
   $langpair_current=$row[0];$current_customerid=$row[1];
   print "<font class='red'>".$LRV['message_listadd_success']."</font><br><br>";
   if ( $site_language_short == 'en' ){
   if ($langpair_current!=$langpair) print $LRV['message_current_list_wrong_langpair'].
				'&nbsp;<span class="link2"><a href="http://lingomoto.com/'.$LRV['settings'].
				'.html">'.$LRV['link_change'].'</a></span><br><br>'; } else {
   if ($langpair_current!=$langpair) print $LRV['message_current_list_wrong_langpair'].
				'&nbsp;<span class="link2"><a href="http://'.$site_language_short.'.lingomoto.com/'.$LRV['settings'].
				'.html">'.$LRV['link_change'].'</a></span><br><br>'; }
   }
   if ($current_customerid == $customerid) print $LRV['message_current_list_own_list'];
}	
 
function edit_list()
{
   global $LRV,$site_language;
    for ($count=1; $count<=20; $count++)
   {
      if ($_REQUEST["submit$count"] and !$zurueck)$edit=$count;
   }
   $list_id= $_REQUEST["list_id$edit"];
   $list_name= $_REQUEST["list_name"];
   $query= "UPDATE vocable_lists
            SET listname='$list_name'
            WHERE listid=$list_id ";
   $resource=mysql_query($query); //print $query;
   print "<font class='red'>{$LRV['message_list_changed']}</font> <BR><BR>";
} 

switch($site_language_short)
    {
        case 'de': require ('kopf.html');break;
        case 'es': require ('cabeza.html');break;
        case 'ru': require ('header.html');break;
        case 'en': require ('header.html');break;
        default: require ('header.html');
    }

// <!-- horizontal column -->
print '<div>';
require ('horizontal.html');
print '</div>';

// <!-- Left Column -->
print '<div id="left_col">';
switch($site_language_short)
    {
        case 'de': require ('vertikal.html');break;
        case 'es': require ('vertical.html');break;
        case 'ru': require ('vertical.html');break;
        case 'en': require ('vertical.html');break;
        default: require ('vertical.html');
    }
print '</div>';

// <!-- Content -->
print "<div id='content'>";
print "<div id='block5'>";


if ($_SESSION['logini']== false and ($_REQUEST['owner_choice']=='own' or $_REQUEST['hinzufuegen']) and $error == '' ) {
switch($site_language_short)
    {
        case 'de': require_once ('loginformular.html');break;
        case 'es': require_once ('loginformular.html');break;
        case 'ru': require_once ('loginform.html');break;
        case 'en': require_once ('loginform.html');break;
        default: require_once ('loginform.html');
    }
print '<br/><p><a href="'.$_SERVER["PHP_SELF"]. '" class="lostpassword">'.$LRV['link_back_to_lists'].'</a></p>';
}  

// request for login, if errors in loginformulartop
elseif ($_SESSION['logini']== false and $error <> '' ) {
switch($site_language_short)
    {
        case 'de': require_once ('loginformular.html');break;
        case 'es': require_once ('loginformular.html');break;
        case 'ru': require_once ('loginform.html');break;
        case 'en': require_once ('loginform.html');break;
        default: require_once ('loginform.html');
    }
     
}

// if new password, request for change of password
elseif ( $newpass == 1 ) //wenn das obere wieder eingesetzt <- hier elseif
{
$passwo = isset($_REQUEST['passwo']) ? $_REQUEST['passwo'] : '1';
$passwo1 = isset($_REQUEST['passwo1']) ? $_REQUEST['passwo1'] : '1';
$passwo2 = isset($_REQUEST['passwo2']) ? $_REQUEST['passwo2'] : '1';
$ok='';
switch($site_language_short)
    {
        case 'de': require_once ('neues-passwort.html');break;
        case 'es': require_once ('password-nuevo.html');break;
        case 'ru': require_once ('new-password.html');break;
        case 'en': require_once ('new-password.html');break;
        default: require_once ('new-password.html');
    }
 
}
else 
{

$zurueck=$_REQUEST['zurueck'];

//find submitted image link and put number, matched list_id and action into variable
//INFO: this is a workaround, because input type image cannot transfer the content of the "value"-attribute
// -> therefore always a hidden input for every image link (which is identified by its number) with the list_id of it  
for ($count=1; $count<=20; $count++)
{
	//this is for the number of the list
    if (($_REQUEST["submit$count"]=='Ansehen' or $_REQUEST["view$count"]) and !$zurueck){$view=$count;$list_id= $_REQUEST["list_id$count"];}
    if (($_REQUEST["submit$count"]=='Editieren' or $_REQUEST["edit$count"]) and !$zurueck){$edit=$count;$list_id= $_REQUEST["list_id$count"];}
    if (($_REQUEST["submit$count"]=='Loeschen' or $_REQUEST["delete$count"]) and !$zurueck){$delete=$count;$list_id= $_REQUEST["list_id$count"];}
    if (($_REQUEST["submit$count"]=='Hinzufuegen' or $_REQUEST["add$count"]) and !$zurueck){$add=$count;$list_id= $_REQUEST["list_id$count"];}
}

//this is for the id of the row in vocable_lists_words
foreach ($_REQUEST as $key=>$value)
{
	if (strpos($key, "delete_row") === 0)
	{
	   $delete_row=substr($key,10);
	}
}

   if (($view or $delete or $edit or $add or $delete_row or $_REQUEST['weiter'] or $_REQUEST['undo_rating']) and !$_REQUEST['loeschen'] and !$_REQUEST['hinzufuegen'] and !$_REQUEST["editieren"]) 
   { //if one of the image links has been clicked or if "Weiter" inside the list_change_page was clicked 
      print_list_change_page($list_id,$view,$edit,$delete,$add,$delete_row); 
      //this is the second page where you can view, edit, delete, etc. the current list
   }
   else print_all_lists_page(); //this is the page that is shown first displaying the lists depending on the selection
   //that is made on top  


}

echo '</div>';
echo '</div>';
echo '<div id="adverts">';
echo '<div id="adbox"></div>';
echo '</div>';

switch($site_language_short)
    {
        case 'de': require ('fuss.html');break;
        case 'es': require ('pie.html');break;
        case 'ru': require ('footer.html');break;
        case 'en': require ('footer.html');break;
        default: require ('footer.html');
    }

function printHtmlLink($strLocation,$strTitle)
{
	print "<a href=\"$strLocation\">$strTitle</a>";
}    
?>

</body>
</html>